package com.chinapost.util;

import java.io.UnsupportedEncodingException;

public class MyUtil {

	public static String arrayToSql(String[] str){
		String result ="";
		for (int i=0;i<str.length;i++){
			if (i!=str.length-1){
			result += "sum(t."+str[i]+"),";
			}else{
				result += "sum(t."+str[i]+")";
			}
		}
		return result;
	}
	public static String arrayToDatagrid(String[] a1,String[] a2){
		String result="";
		for (int i=0;i<a1.length;i++){
			result +=  "{title :\""+a1[i]+"\","+"field : \""+a2[i]+"\","+"align :\"center\","+" width : 80},";
                }
		return result.substring(0,result.length()-1);
		}
	
	/**
	 * 截取字符串，通过先变成byte[]，再截取，解决中文问题
	 */
	public static String substr(byte[] bytes,int start,int count){
		String result=null;
		try {
			result= new String(bytes,start,count,"GBK");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return result;
	}
	
	/**
	 * 根据字符的位置删除byte[]数组中的一个元素
	 */
	 public static byte[] delByte(byte[] bs, int index)
	    {
	        int length = bs.length - 1;
	        byte[] ret = new byte[length];
	         
	        System.arraycopy(bs, 0, ret, 0, index);
	        System.arraycopy(bs, index + 1, ret, index, length - index);
	         
	        return ret;
	    }
}
